package com.web.hawaste.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.web.hawaste.entity.AppVersion;
import com.web.hawaste.service.IAppVersionService;
import com.web.hawaste.utils.PageInfo;
import com.web.hawaste.utils.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Suzy
 * @since 2022-09-26
 */
@RestController
@RequestMapping("/manager/app")
public class AppVersionController {
    @Autowired
    private IAppVersionService appVersionService;

    /**
     * 方法名: select
     * 描述: 获取分页数据
     *
     * @param current 当前页码
     * @param size    每页显示数量
     * @return com.web.hawaste.utils.ResultBean<com.baomidou.mybatisplus.extension.plugins.pagination.Page>
     * @date 2022/9/28 22:51
     * @auther YangSuzy
     **/
    @GetMapping("/select")
    public ResultBean<Page> select(
            @RequestParam("current") Integer current,
            @RequestParam("size") Integer size) {
        PageInfo<AppVersion> page = appVersionService.page(new PageInfo<AppVersion>(current, size));
        //设置分页对象的导航栏数据
        page.setNavigatePage();
        return ResultBean.ok(page);
    }

    /**
     * 方法名: saveOrUpdate
     * 描述: 添加或更新
     *
     * @param app
     * @return com.web.hawaste.utils.ResultBean
     * @date 2022/9/28 22:52
     * @auther YangSuzy
     **/
    @PostMapping("/saveOrUpdate")
    public ResultBean saveOrUpdate(@RequestBody() AppVersion app) {
        System.out.println("app唯一标识：" + app.getId());
        appVersionService.saveOrUpdate(app);
        return ResultBean.ok();
    }

    @GetMapping("/selectOne")
    public ResultBean selectOne(Long id) {
        AppVersion app = appVersionService.getById(id);
        System.out.println("编辑：" + app);
        return ResultBean.ok(app);
    }

    @GetMapping("/delete")
    public ResultBean delete(Long id) {
        appVersionService.removeById(id);
        return ResultBean.ok();
    }
}
